//
//  EpointWSTask.m
//  EpointFrame5
//
//  Created by 李亚春 on 14-1-16.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "EpointWSTask.h"
#import "EpointStringUtil.h"


@implementation EpointWSTask

-(NSString *)getMobileOAWebserviceURL
{
    return [EpointBizTools getMobileOAWebserviceURL];
}

-(BOOL)validateXMLWS:(NSString *)obj
{
    NSString *msg;
    BOOL isQuestNormal = NO;
    if (obj==nil) {
        msg = @"网络连接超时！";
    }
    else
    {
        NSString *bs = (NSString *)obj;
        NSString *ReturnInfo = [EpointStringUtil getXMLFormatedAttribute:bs :@"ReturnInfo"];
        NSString *Status = [EpointStringUtil getXMLFormatedAttribute:ReturnInfo :@"Status"];
        if([Status isEqualToString:@"True"])
        {
            isQuestNormal = YES;
        }
        else if([Status isEqualToString:@"False"])
        {
            NSString *Description = [EpointStringUtil getXMLFormatedAttribute:ReturnInfo :@"Description"];
            Description = [Description stringByReplacingOccurrencesOfString:@"<![CDATA[" withString:@""];
            Description = [Description stringByReplacingOccurrencesOfString:@"]]>" withString:@""];
            msg = [NSString stringWithFormat:@"%@",Description];
        }
        else
        {
            msg = @"数据请求失败！";
        }
    }
    
    if (isQuestNormal==NO) {
        [self exeFailureWithMessage:msg];
    }
    
    return isQuestNormal;
}

-(NSMutableArray *)validateXMLWS2:(NSString *)obj
{
    NSMutableArray *result = [[NSMutableArray alloc]init];
    NSString *msg;
    NSString *isQuestNormal = @"0";
    if (obj==nil) {
        msg = @"网络连接超时！";
    }
    else
    {
        NSString *bs = (NSString *)obj;
        NSString *ReturnInfo = [EpointStringUtil getXMLFormatedAttribute:bs :@"ReturnInfo"];
        NSString *Status = [EpointStringUtil getXMLFormatedAttribute:ReturnInfo :@"Status"];
        if([Status isEqualToString:@"True"])
        {
            isQuestNormal = @"1";
            msg = @"";
        }
        else if([Status isEqualToString:@"False"])
        {
            NSString *Description = [EpointStringUtil getXMLFormatedAttribute:ReturnInfo :@"Description"];
            Description = [Description stringByReplacingOccurrencesOfString:@"<![CDATA[" withString:@""];
            Description = [Description stringByReplacingOccurrencesOfString:@"]]>" withString:@""];
            msg = [NSString stringWithFormat:@"%@",Description];
        }
        else
        {
            msg = @"数据请求失败！";
        }
    }
    
    [result addObject:isQuestNormal];
    [result addObject:msg];
    
    return result;
}

-(void)genUIData:(NSString *)isSuccss message:(NSString *)message
{
    NSMutableArray *pArr = [[NSMutableArray alloc]init];
    [pArr addObject:isSuccss];
    [pArr addObject:message];
    [self sendDataRefreshUI:pArr];
}

-(void)exeFailureWithMessage:(NSString *)msg
{
    [self genUIData:@"0" message:msg];
}

-(void)exeSuccess
{
    [self genUIData:@"1" message:@""];
}

-(void)exeSuccessWithData:(NSObject *)obj
{
    NSMutableArray *pArr = [[NSMutableArray alloc]init];
    [pArr addObject:@"1"];
    [pArr addObject:@""];
    [pArr addObject:obj];
    [self sendDataRefreshUI:pArr];
}

-(BOOL)isNetWorkAvailable
{
    EpointAppDelegate *dele = [[UIApplication sharedApplication]delegate];
    if (dele.netWorkStatus==0) {
        return NO;
    }
    else
    {
        return YES;
    }
}

-(void)print:(NSString *)method withVali:(NSString *)vali withXML:(NSString *)xml withBs:(NSString *)bs{
    NSLog(@"方法名称：%@",method);
    NSLog(@"输入参数Validata：%@",vali);
    NSLog(@"输入参数XML：%@",xml);
    NSLog(@"返回参数：%@",bs);
}

@end
